package HomeWork;

/**
 * @description:
 * @Author yyp
 * @time
 */
public class HomeWork06 {
    public static void main(String[] args) {
        Person p = new Person("tang",new Horse());
        p.river();
        p.river();
        p.normal();
        p.normal();
    }
}
interface Vehicles{
    public void work();
}
class Boat implements Vehicles{
    @Override
    public void work() {
        System.out.println("造船");
    }
}
class Horse implements Vehicles{
    @Override
    public void work() {
        System.out.println("造马");
    }
}
class VehiclesFactory {
    public static Boat getBoat(){
        System.out.println("获得船");
        return new Boat();
    }
    public static Horse getHorse(){
        System.out.println("获得马");
        return new Horse();
    }
}
class Person{
    public String name;
    public Vehicles vehicles;
    public Person(String name, Vehicles vehicles) {
        this.name = name;
        this.vehicles = vehicles;
    }
    public void river(){
        if(!(vehicles instanceof Boat)){
            vehicles = VehiclesFactory.getBoat();
        }
        vehicles.work();
    }
    public void normal(){
        if(!(vehicles instanceof Horse)){
            vehicles = VehiclesFactory.getHorse();
        }
        vehicles.work();
    }
}